package com.sndscl.rpc.spring;

import com.sndscl.rpc.call.RpcCallInvocationHandler;
import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.Proxy;

/**
 * @Description
 * @Author lsh
 * @Date 2020/10/16 16:11
 **/
public class SndsclRpcBenFactory<T> implements FactoryBean<T> {

    private Class<?> interfaceType;

    public SndsclRpcBenFactory(Class<?> interfaceType){
        this.interfaceType = interfaceType;
    }

    @Override
    public T getObject() throws Exception {
        return (T) Proxy.newProxyInstance(interfaceType.getClassLoader(),new Class[] { interfaceType },new RpcCallInvocationHandler()) ;
    }

    @Override
    public Class<?> getObjectType() {
        return interfaceType;
    }
}
